<%= form_required_explanation %>

<% unless single_initiative_type? %>
  <%= form.select :type_id,
                  initiative_type_options,
                  {},
                  {
                    disabled: !@form.signature_type_updatable?,
                    "data-scope-selector": "initiative_decidim_scope_id",
                    "data-scope-id": form.object.scope_id.to_s,
                    "data-scope-search-url": decidim_initiatives.initiative_type_scopes_search_url,
                    "data-signature-types-selector": "initiative_signature_type",
                    "data-signature-type": current_initiative.signature_type,
                    "data-signature-types-search-url": decidim_initiatives.initiative_type_signature_types_search_url
                  } %>
<% end %>

<%= form.text_field :title, autofocus: true, disabled: !allowed_to?(:update, :initiative, initiative: current_initiative), value: translated_attribute(@form.title), data: { controller: "character-counter" } %>

<%= text_editor_for(form, :description, toolbar: :content, lines: 8, disabled: !allowed_to?(:update, :initiative, initiative: current_initiative), value: translated_attribute(@form.description)) %>

<% if @form.state_updatable? %>
  <%= form.select :state, Decidim::Initiative.states.keys.map { |state| [I18n.t(state, scope: "decidim.initiatives.admin_states"), state] }, {} %>
<% end %>

<%= form.select :scope_id, @form.available_scopes.map { |scope| [translated_attribute(scope.scope_name), scope.scope&.id] }, {}, { disabled: !@form.state_updatable? } %>

<% if can_edit_custom_signature_end_date?(current_initiative) %>
  <%= form.date_field :signature_end_date, disabled: !allowed_to?(:update, :initiative, initiative: current_initiative) %>
<% end %>

<% if current_initiative.area_enabled? %>
  <%= form.areas_select :area_id,
                        areas_for_select(current_organization),
                        {
                          selected: current_initiative.decidim_area_id,
                          include_blank: current_initiative.decidim_area_id.blank? || current_initiative.created?
                        },
                        disabled: !@form.area_updatable? %>
<% end %>

<% signature_type_options = signature_type_options(form.object) %>
<% if signature_type_options.length == 1 %>
  <%= form.hidden_field :signature_type %>
<% else %>
  <%= form.select :signature_type, [], {}, { disabled: !@form.signature_type_updatable? } %>
<% end %>

<% if current_initiative.type.attachments_enabled? %>
  <%= form.attachment :documents,
                      multiple: true,
                      label: t("decidim.initiatives.form.add_attachments"),
                      button_label: t("decidim.initiatives.form.add_attachments"),
                      button_class: "button button__lg button__transparent-secondary w-full",
                      button_edit_label: t("decidim.initiatives.form.edit_attachments"),
                      help_text: t("decidim.initiatives.form.attachment_legend") %>

  <%= form.attachment :photos,
                      multiple: true,
                      label: t("decidim.initiatives.form.add_image"),
                      button_label: t("decidim.initiatives.form.add_image"),
                      button_class: "button button__lg button__transparent-secondary w-full",
                      button_edit_label: t("decidim.initiatives.form.edit_image"),
                      help_text: t("decidim.initiatives.form.image_legend") %>
<% end %>

<% if current_initiative.type.promoting_committee_enabled? %>
  <%= render partial: "committee_members" %>
<% end %>

<%= append_javascript_pack_tag "decidim_initiatives" %>
<%= append_stylesheet_pack_tag "decidim_initiatives", media: "all" %>
